package com.apes.project.jekunAuto.intf.aut;

import com.apes.scm.rbac.model.User;
import com.apes.scm.rbac.service.UserService;
import com.apestech.framework.json.JSONArray;
import com.apestech.framework.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("intfMasterDataService")
public class MasterDataService {

    @Autowired
    public UserService userService;

    /**
     * 同步YYERP的操作员密码信息
     * @param userArray 需要更新的操作员列表
     * @throws Exception 异常
     */
    public void updatePassWordFromYYERP(JSONArray userArray) throws Exception {
        int iCount = userArray.size();
        for(int i=0; i<iCount; i++){
            JSONObject userOutside = userArray.getJSONObject(i);
            User user = userService.getUser(userOutside.getString("CZYID"));
            if (user == null){
                user = new User();
                user.setOrigin(userOutside.getString("CZYID"));
                user.setName(userOutside.getString("CZYMC"));
                user.setPassword(userOutside.getString("CZYMM"));
                userService.synchronous(user);
            }else{
                user.setName(userOutside.getString("CZYMC"));
                user.setPassword(userOutside.getString("CZYMM"));
                userService.synchronous(user);
            }
        }
    }

}
